﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace MyServer.Todo.Infrastructure.DatabaseContext.EntityConfigurations
{
    public class TodoConfig : IEntityTypeConfiguration<Domain.Aggregates.TodoGroupAggregate.Todo>
    {
        public void Configure(EntityTypeBuilder<Domain.Aggregates.TodoGroupAggregate.Todo> builder)
        {
            builder.ToTable("todo");

            builder.HasKey(_ => _.Id);
            builder.Property(_ => _.Id)
                .HasColumnName("id")
                .HasMaxLength(36)
                .IsRequired();

            builder.Property(_ => _.Name)
                .HasColumnName("name");

            builder.Property(_ => _.Notes)
                .HasColumnName("notes");

            builder.Property(_ => _.CreationTime)
                .HasColumnName("creation_time");

            builder.Property(_ => _.TodoStatus)
                .HasColumnName("todo_status");

            builder.HasOne(_ => _.Settings).WithOne().HasForeignKey<TodoSettings>("todo_id").IsRequired().OnDelete(DeleteBehavior.Cascade);

        }
    }
}
